package dian.qing.li.demo.security.exception;

import org.springframework.http.HttpStatus;

public class RestException extends RuntimeException {
    private static final long serialVersionUID = -2365683334848201701L;
    private final int code;

    public RestException(int code, String msg) {
        super(msg);
        this.code = code == 0 ? 1 : code;
    }

    public RestException(String msg) {
        super(msg);
        this.code = 1;
    }

    public RestException(RuntimeException e) {
        super(e.getMessage());
        this.code = HttpStatus.INTERNAL_SERVER_ERROR.value();
    }

    public int getCode() {
        return this.code;
    }

    public String getMsg() {
        return super.getMessage();
    }
}
